/**
 */
package de.thwildau.tm.moses.thrift.thrift.impl;

import de.thwildau.tm.moses.thrift.thrift.Field;
import de.thwildau.tm.moses.thrift.thrift.Function;
import de.thwildau.tm.moses.thrift.thrift.FunctionType;
import de.thwildau.tm.moses.thrift.thrift.ThriftPackage;
import de.thwildau.tm.moses.thrift.thrift.Throws;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.MinimalEObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Function</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FunctionImpl#getFunctionType <em>Function Type</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FunctionImpl#getName <em>Name</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FunctionImpl#getFields <em>Fields</em>}</li>
 *   <li>{@link de.thwildau.tm.moses.thrift.thrift.impl.FunctionImpl#getThrowsDecl <em>Throws Decl</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class FunctionImpl extends MinimalEObjectImpl.Container implements Function
{
  /**
   * The cached value of the '{@link #getFunctionType() <em>Function Type</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFunctionType()
   * @generated
   * @ordered
   */
  protected FunctionType functionType;

  /**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected static final String NAME_EDEFAULT = null;

  /**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
  protected String name = NAME_EDEFAULT;

  /**
   * The cached value of the '{@link #getFields() <em>Fields</em>}' containment reference list.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getFields()
   * @generated
   * @ordered
   */
  protected EList<Field> fields;

  /**
   * The cached value of the '{@link #getThrowsDecl() <em>Throws Decl</em>}' containment reference.
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @see #getThrowsDecl()
   * @generated
   * @ordered
   */
  protected Throws throwsDecl;

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  protected FunctionImpl()
  {
    super();
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  protected EClass eStaticClass()
  {
    return ThriftPackage.Literals.FUNCTION;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public FunctionType getFunctionType()
  {
    return functionType;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetFunctionType(FunctionType newFunctionType, NotificationChain msgs)
  {
    FunctionType oldFunctionType = functionType;
    functionType = newFunctionType;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ThriftPackage.FUNCTION__FUNCTION_TYPE, oldFunctionType, newFunctionType);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setFunctionType(FunctionType newFunctionType)
  {
    if (newFunctionType != functionType)
    {
      NotificationChain msgs = null;
      if (functionType != null)
        msgs = ((InternalEObject)functionType).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FUNCTION__FUNCTION_TYPE, null, msgs);
      if (newFunctionType != null)
        msgs = ((InternalEObject)newFunctionType).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FUNCTION__FUNCTION_TYPE, null, msgs);
      msgs = basicSetFunctionType(newFunctionType, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FUNCTION__FUNCTION_TYPE, newFunctionType, newFunctionType));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public String getName()
  {
    return name;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setName(String newName)
  {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FUNCTION__NAME, oldName, name));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public EList<Field> getFields()
  {
    if (fields == null)
    {
      fields = new EObjectContainmentEList<Field>(Field.class, this, ThriftPackage.FUNCTION__FIELDS);
    }
    return fields;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public Throws getThrowsDecl()
  {
    return throwsDecl;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public NotificationChain basicSetThrowsDecl(Throws newThrowsDecl, NotificationChain msgs)
  {
    Throws oldThrowsDecl = throwsDecl;
    throwsDecl = newThrowsDecl;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, ThriftPackage.FUNCTION__THROWS_DECL, oldThrowsDecl, newThrowsDecl);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setThrowsDecl(Throws newThrowsDecl)
  {
    if (newThrowsDecl != throwsDecl)
    {
      NotificationChain msgs = null;
      if (throwsDecl != null)
        msgs = ((InternalEObject)throwsDecl).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FUNCTION__THROWS_DECL, null, msgs);
      if (newThrowsDecl != null)
        msgs = ((InternalEObject)newThrowsDecl).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - ThriftPackage.FUNCTION__THROWS_DECL, null, msgs);
      msgs = basicSetThrowsDecl(newThrowsDecl, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, ThriftPackage.FUNCTION__THROWS_DECL, newThrowsDecl, newThrowsDecl));
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs)
  {
    switch (featureID)
    {
      case ThriftPackage.FUNCTION__FUNCTION_TYPE:
        return basicSetFunctionType(null, msgs);
      case ThriftPackage.FUNCTION__FIELDS:
        return ((InternalEList<?>)getFields()).basicRemove(otherEnd, msgs);
      case ThriftPackage.FUNCTION__THROWS_DECL:
        return basicSetThrowsDecl(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public Object eGet(int featureID, boolean resolve, boolean coreType)
  {
    switch (featureID)
    {
      case ThriftPackage.FUNCTION__FUNCTION_TYPE:
        return getFunctionType();
      case ThriftPackage.FUNCTION__NAME:
        return getName();
      case ThriftPackage.FUNCTION__FIELDS:
        return getFields();
      case ThriftPackage.FUNCTION__THROWS_DECL:
        return getThrowsDecl();
    }
    return super.eGet(featureID, resolve, coreType);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @SuppressWarnings("unchecked")
  @Override
  public void eSet(int featureID, Object newValue)
  {
    switch (featureID)
    {
      case ThriftPackage.FUNCTION__FUNCTION_TYPE:
        setFunctionType((FunctionType)newValue);
        return;
      case ThriftPackage.FUNCTION__NAME:
        setName((String)newValue);
        return;
      case ThriftPackage.FUNCTION__FIELDS:
        getFields().clear();
        getFields().addAll((Collection<? extends Field>)newValue);
        return;
      case ThriftPackage.FUNCTION__THROWS_DECL:
        setThrowsDecl((Throws)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public void eUnset(int featureID)
  {
    switch (featureID)
    {
      case ThriftPackage.FUNCTION__FUNCTION_TYPE:
        setFunctionType((FunctionType)null);
        return;
      case ThriftPackage.FUNCTION__NAME:
        setName(NAME_EDEFAULT);
        return;
      case ThriftPackage.FUNCTION__FIELDS:
        getFields().clear();
        return;
      case ThriftPackage.FUNCTION__THROWS_DECL:
        setThrowsDecl((Throws)null);
        return;
    }
    super.eUnset(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public boolean eIsSet(int featureID)
  {
    switch (featureID)
    {
      case ThriftPackage.FUNCTION__FUNCTION_TYPE:
        return functionType != null;
      case ThriftPackage.FUNCTION__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case ThriftPackage.FUNCTION__FIELDS:
        return fields != null && !fields.isEmpty();
      case ThriftPackage.FUNCTION__THROWS_DECL:
        return throwsDecl != null;
    }
    return super.eIsSet(featureID);
  }

  /**
   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  @Override
  public String toString()
  {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //FunctionImpl
